package com.tool.genxml.entity;

import lombok.Data;
import org.apache.poi.ss.util.CellRangeAddress;

/**
 * 合并的单元格对象
 * @author: zhoubin
 * @date: 2024/3/26
 */
@Data
public class MergedRegion {

    /**
     * 开始列号
     */
    private int startColumn;
    /**
     * 结束列号
     */
    private int endColumn;

    /**
     * 总行号
     */
    private int lineCount;

    /**
     * 开始行号
     */
    private int startRow;

    /**
     * 结束行号
     */
    private int endRow;

    /**
     * 值
     */
    private String val;

    public static MergedRegion convertMergedRegion(CellRangeAddress address) {
        MergedRegion mergedRegion = new MergedRegion();
        mergedRegion.setStartRow(address.getFirstRow());
        mergedRegion.setEndRow(address.getLastRow());
        mergedRegion.setStartColumn(address.getFirstColumn());
        mergedRegion.setEndColumn(address.getLastColumn());

        mergedRegion.setLineCount(mergedRegion.getEndRow() - mergedRegion.getStartRow() + 1);
        return mergedRegion;
    }
}
